import React from "react";

import BaseExecuter from "../common/BaseExecuter";
import Constants from "../../common/Constants";

import DataManager from "../../datas/DataManager";

export default class SportExecuter extends BaseExecuter {
  constructor() {
    super();
  }

  execute(action) {
    switch (action.name) {
      case "SportSendStepAction":
        this._sendSteps(action);
        break;
      case "SportRequestUserListAction":
        this._requestUserList(action);
        break;
      case "SportRequestSelfDataAction":
        this._requestSelfData(action);
        break;
      case "SportReadLocalDataAction":
        this._readLocalData(action);
        break;
      case "SportRequestSelfListDataAction":
        this._requestSelfListData(action);
        break;
      case "SportJumpAction":
        this._sportJump(action);
        break;
      case "SportSendActivityStepsAction":
        this._sendActivitySteps(action);
        break;
      case "SportHealthConfigAction":
        this._requestHealthConfig(action);
        break;
      case "SporSendActivityStepsDailyAction":
        this._sendActivityStepsDaily(action);
        break;
      case "SportGetTodayStepsAction":
        this._getTodaySteps(action);
        break;
      case "SportDibiaoRequestSelfData":
        this._requestDibiaoSelfData(action);
        break;
      case "SportDibiaoDetailRequestSelfData":
        this._requestDibiaoDetailSelfData(action);
        break;
      case "SportGetStepConfigAction":
        this._getStepConfig(action);
        break;
      case "SportOptionsStepConfigAction":
        this._optionsStepConfig(action);
        break;
    }
  }

  _getStepConfig(action) {
    this._sendRequestCommonResponse(action, "getStepConfig");
  }
  _requestHealthConfig(action) {
    this._sendRequestCommonResponse(action, "requestHealthConfig");
  }
  _optionsStepConfig(action) {
    this._sendRequestCommonResponse(action, "optionsStepConfig");
  }

  _requestDibiaoSelfData(action) {
    this._sendRequestCommonResponse(action, "requestDibiaoSelfData");
  }

  _requestDibiaoDetailSelfData(action) {
    this._sendRequestCommonResponse(action, "requestDibiaoDetailSelfData");
  }

  _sendActivitySteps(action) {
    this._sendRequestCommonResponse(action, "sendActivitySteps");
  }
  _sportJump(action){
    this._sendRequestCommonResponse(action, "sportJump");;
  }
  // 提交步数
  _sendActivityStepsDaily(action) {
    this._sendRequestCommonResponse(action, "sendActivityStepsDaily");
  }

  //读取步数
  _readLocalData(action) {
    //action.data  {type:{"step", "distance"}, day:day, callback:callback}
    this._sendRequestCommon(action, "readHealthyKitData");
  }

  _requestSelfData(action) {
    this._sendRequestCommonResponse(action, "requestSelfData");
  }

  _requestSelfListData(action) {
    this._sendRequestCommonResponse(action, "requestSelfListData");
  }

  _getTodaySteps(action) {
    let step = DataManager.callMethod(
      Constants.MODULE_TYPE.SPORT,
      "getTodayStep"
    );
    action.finish(step);
  }

  _sendSteps(action) {
    DataManager.callMethod(Constants.MODULE_TYPE.SPORT, "sendSteps", [
      (data, isSucceed, response) => {
        action.finish(data, isSucceed, response);
        action.data();
      }
    ]);
  }

  _requestUserList(action) {
    this._sendRequestCommon(action, "requestUserList");
  }

  _getModuleType() {
    return Constants.MODULE_TYPE.SPORT;
  }
}
